package arithmetic;

/**
 * 反转数组
 */
public class Rotate_array {
    public static void main(String[] args) {
        /* 先全部翻转再分别翻转前面一部分后一部分 */
        int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        System.out.println("翻转前：");
        for (int element : a) {
            System.out.println(element);
        }
        int number = 3;
        int i = 0;
        int j = 8;
        while (i < j) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
            i++;
            j--;
        }
        int k = 0;
        int m = number - 1;
        while (k < m) {
            int temp = a[k];
            a[k] = a[m];
            a[m] = temp;
            k++;
            m--;
        }
        int t = 8;
        while (number < t) {
            int temp = a[number];
            a[number] = a[t];
            a[t] = temp;
            number++;
            t--;
        }
        System.out.println("翻转后");
        for (int element : a) {
            System.out.println(element);
        }
    }
}
